<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>列表</title>
</head>
<body>
	<%@ include file="/web/front/title/start.jsp"%>

	<div class="danpin center">

		<div class="biaoti center">阴阳师式神</div>
		
		<div class="danpin center" id="divbody">
			
		</div>
	</div>
	
		<input type="hidden" name="pageIndex" value="1">
		<input type="hidden" name="pageLimit" value="10">
		<div id='pageInfo' style="text-align: right;padding-right: 30px"></div>

	<%@ include file="/web/front/title/end.jsp"%>
	
	<script type="text/javascript">
		
		var parentCode= '<%=request.getParameter("code2")==null?"":request.getParameter("code2")%>'
		var productType1='<%=request.getParameter("code1")==null?"":request.getParameter("code1")%>'
		var searchParam = {
				parentCode:parentCode,
				pageIndex:$("input[name='pageIndex']").val(),
				pageLimit:$("input[name='pageLimit']").val()
			}
			
		refresh();
		function refresh(){
			if(productType1!="")//查一级
				ajax({code:productType1},'/product/selectAll.do','json',pageList);
			else//查二级/全部
				ajax(searchParam,'/product/selectModel.do','json',pageList);		
			}
	
		function pageList(data){
			var pageIndex = $("input[name='pageIndex']").val();
			var pageLimit = $("input[name='pageLimit']").val();
			setPageInfo('pageInfo',data.count,pageIndex,pageLimit,function(obj,first){//obj当前分页的所有选项值;first是否是首次，一般用于初始加载判断
				$("input[name='pageIndex']").val(obj.curr);//得到当前页，以便向服务端请求对应页的数据
				$("input[name='pageLimit']").val(obj.limit);//得到每页显示的条数
				searchParam.pageIndex = $("input[name='pageIndex']").val()
				searchParam.pageLimit = $("input[name='pageLimit']").val()
			if(!first){refresh()}//首次不执行
			});
			
			var html = "";
			$("#divbody").html(html);
			var t = 1;
			var html2 = "";
			$.each(data.data,function(index,d){
				if(d.status == "1"){// status = 1为上架状态
					html2 += "<div class='mingxing fl mb20' style='border: 2px solid #fff; width: 230px; cursor: pointer;' onmouseout='this.style.border=\"2px solid #fff\"' onmousemove='this.style.border=\"2px solid red\"'>";
					html2 += "<div class='sub_mingxing'><a href='javascript:todetails(\"" + d.code + "\");' >"
				 		  + "<img src='/image/"+ d.url +"' alt=''></a></div>";
				 	html2 += "<div class='pinpai'><a href='javascript:todetails(\"" + d.code + "\");'"
				 		  + "target='_blank'>"+ d.name +"</a></div>";
				 	html2 += "<div class='youhui'>" + d.descr + "</div>";
				 	html2 += "<div class='jiage'>"+ d.price +"元</div></div>";
				 	t++;
				 	if(t%6==0){//五个换行
						html = "<div class='main center mb20'>"+ html2 +"</div>"
						$("#divbody").append(html); 
						html = "";
						html2 = "";
					}
				}
			})
			if(html2!=''){
				html += "<div class='main center mb20'>"+ html2 +"</div>";
				$("#divbody").append(html);
			}
		}
		
		ajax({parentCode:'type1'},'/cate/getAll.do','json',typeshow);
		function typeshow(data){
			var html1 = "";
			$.each(data,function(i,dom){
				var code = dom.code;
				if(code == 'type1')return;	
				var t1 = "<li><a href='javascript:fenlei(\""+code+"\",1);'>"+dom.name+"</a>"
				html1 += t1 +"</li>";
			});
			$("#fenlei1").html(html1);	
		}
		
		function todetails(code){
			toJsp('/web/front/details.jsp?code=' + code);	
		}
		
		function fenlei(code,i){
			toJsp('/web/front/list.jsp?code'+i+'=' + code, refresh)
		}
		
	</script>
</body>
</html>